package cn.adelyn.blog.file.dao;

import cn.adelyn.blog.file.dao.mapper.FileInfoMapper;
import cn.adelyn.blog.file.pojo.model.FileInfoModel;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FileInfoDAOService {

    @Autowired
    FileInfoMapper fileInfoMapper;

    public FileInfoModel getFileInfoById(Long fileId) {
        return fileInfoMapper.selectById(fileId);
    }

    public void insertFileInfo(FileInfoModel fileInfoModel) {
        fileInfoMapper.insert(fileInfoModel);
    }

    public void deleteFileInfo(Long fileId) {
        fileInfoMapper.deleteById(fileId);
    }

    public void updateFileInfo(FileInfoModel fileInfoModel) {
        QueryWrapper<FileInfoModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(StrUtil.isBlank(fileInfoModel.getFileName()), FileInfoModel::getFileId, fileInfoModel.getFileId());

        fileInfoMapper.update(fileInfoModel, queryWrapper);
    }


}
